﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using FarPoint.Win.Chart;
using System.Threading;
using System.Globalization;

namespace Simulacion.Forms
{
    public partial class MainForm : Form
    {
        #region Constructor

        public MainForm()
        {
            InitializeComponent();

            this.cbFruitDistr.SelectedIndex = 0;
            this.cbPeriodo.SelectedIndex = 0;

            this._orange = new Fruits.Orange();
            this._banana = new Fruits.Banana();
            this._melon = new Fruits.Melon();
            this._grapefruit = new Fruits.Grapefruit();
            this._nopal = new Fruits.Nopal();
            this._carrot = new Fruits.Carrot();
            this._lemon = new Fruits.Lemon();
            this._perejil = new Fruits.Perejil();
            this._strawberry = new Fruits.Strawberry();
            this._pineapple = new Fruits.Pineapple();
            this._guayaba = new Fruits.Guayaba();
            this._mango = new Fruits.Mango();
        }

        #endregion Constructor

        #region Private Declarations

        private DataSet _initialInventary;
        private DataSet _outputDataSet;
        Fruits.Orange _orange;
        Fruits.Banana _banana;
        Fruits.Melon _melon;
        Fruits.Grapefruit _grapefruit;
        Fruits.Nopal _nopal;
        Fruits.Carrot _carrot;
        Fruits.Lemon _lemon;
        Fruits.Perejil _perejil;
        Fruits.Strawberry _strawberry;
        Fruits.Pineapple _pineapple;
        Fruits.Guayaba _guayaba;
        Fruits.Mango _mango;

        List<string> _monthsCategery = new List<string>();

        List<double> _valuesDemandBanana = new List<double>();
        List<double> _valuesInventaryBanana = new List<double>();

        List<double> _valuesDemandCarrot = new List<double>();
        List<double> _valuesInventaryCarrot = new List<double>();

        List<double> _valuesDemandGrapefruit = new List<double>();
        List<double> _valuesInventaryGrapefruit = new List<double>();

        List<double> _valuesDemandLemon = new List<double>();
        List<double> _valuesInventaryLemon = new List<double>();

        List<double> _valuesDemandMelon = new List<double>();
        List<double> _valuesInventaryMelon = new List<double>();

        List<double> _valuesDemandNopal = new List<double>();
        List<double> _valuesInventaryNopal = new List<double>();

        List<double> _valuesDemandOrange = new List<double>();
        List<double> _valuesInventaryOrange = new List<double>();

        List<double> _valuesDemandPerejil = new List<double>();
        List<double> _valuesInventaryPerejil = new List<double>();

        List<double> _valuesDemandGuayaba = new List<double>();
        List<double> _valuesInventaryGuayaba = new List<double>();

        List<double> _valuesDemandMango = new List<double>();
        List<double> _valuesInventaryMango = new List<double>();

        List<double> _valuesDemandPineapple = new List<double>();
        List<double> _valuesInventaryPineapple = new List<double>();

        List<double> _valuesDemandStrawberry = new List<double>();
        List<double> _valuesInventaryStrawberry = new List<double>();

        #endregion Private Declaratios

        #region Private Methods

        /// <summary>
        /// Run the simulation.
        /// </summary>
        private void RunSimulation()
        {
            this.pbarSimulation.Visible = true;

            this._orange = new Fruits.Orange();
            this._banana = new Fruits.Banana();
            this._melon = new Fruits.Melon();
            this._grapefruit = new Fruits.Grapefruit();
            this._nopal = new Fruits.Nopal();
            this._carrot = new Fruits.Carrot();
            this._lemon = new Fruits.Lemon();
            this._perejil = new Fruits.Perejil();
            this._strawberry = new Fruits.Strawberry();
            this._pineapple = new Fruits.Pineapple();
            this._guayaba = new Fruits.Guayaba();
            this._mango = new Fruits.Mango();

            this._orange.CostoOrdenFijo = this.CostoOrdenFijo;
            this._orange.CostoMantener = this.CostoMantener;
            this._orange.CostoAgotado = this.CostoAgotado;
            this._orange.CostoExtraordinario = this.CostoExtraordinario;

            this._banana.CostoOrdenFijo = this.CostoOrdenFijo;
            this._banana.CostoMantener = this.CostoMantener;
            this._banana.CostoAgotado = this.CostoAgotado;
            this._banana.CostoExtraordinario = this.CostoExtraordinario;

            this._melon.CostoOrdenFijo = this.CostoOrdenFijo;
            this._melon.CostoMantener = this.CostoMantener;
            this._melon.CostoAgotado = this.CostoAgotado;
            this._melon.CostoExtraordinario = this.CostoExtraordinario;

            this._grapefruit.CostoOrdenFijo = this.CostoOrdenFijo;
            this._grapefruit.CostoMantener = this.CostoMantener;
            this._grapefruit.CostoAgotado = this.CostoAgotado;
            this._grapefruit.CostoExtraordinario = this.CostoExtraordinario;

            this._nopal.CostoOrdenFijo = this.CostoOrdenFijo;
            this._nopal.CostoMantener = this.CostoMantener;
            this._nopal.CostoAgotado = this.CostoAgotado;
            this._nopal.CostoExtraordinario = this.CostoExtraordinario;

            this._carrot.CostoOrdenFijo = this.CostoOrdenFijo;
            this._carrot.CostoMantener = this.CostoMantener;
            this._carrot.CostoAgotado = this.CostoAgotado;
            this._carrot.CostoExtraordinario = this.CostoExtraordinario;

            this._lemon.CostoOrdenFijo = this.CostoOrdenFijo;
            this._lemon.CostoMantener = this.CostoMantener;
            this._lemon.CostoAgotado = this.CostoAgotado;
            this._lemon.CostoExtraordinario = this.CostoExtraordinario;

            this._perejil.CostoOrdenFijo = this.CostoOrdenFijo;
            this._perejil.CostoMantener = this.CostoMantener;
            this._perejil.CostoAgotado = this.CostoAgotado;
            this._perejil.CostoExtraordinario = this.CostoExtraordinario;

            this._strawberry.CostoOrdenFijo = this.CostoOrdenFijo;
            this._strawberry.CostoMantener = this.CostoMantener;
            this._strawberry.CostoAgotado = this.CostoAgotado;
            this._strawberry.CostoExtraordinario = this.CostoExtraordinario;

            this._pineapple.CostoOrdenFijo = this.CostoOrdenFijo;
            this._pineapple.CostoMantener = this.CostoMantener;
            this._pineapple.CostoAgotado = this.CostoAgotado;
            this._pineapple.CostoExtraordinario = this.CostoExtraordinario;

            this._guayaba.CostoOrdenFijo = this.CostoOrdenFijo;
            this._guayaba.CostoMantener = this.CostoMantener;
            this._guayaba.CostoAgotado = this.CostoAgotado;
            this._guayaba.CostoExtraordinario = this.CostoExtraordinario;

            this._mango.CostoOrdenFijo = this.CostoOrdenFijo;
            this._mango.CostoMantener = this.CostoMantener;
            this._mango.CostoAgotado = this.CostoAgotado;
            this._mango.CostoExtraordinario = this.CostoExtraordinario;

            this.tpOutput.SelectedTab = this.tpChart;
            this.pbarSimulation.Value = 0;

            this.AddInitialInventaryFruits();
            this.GetOrderInformation();

            _monthsCategery = this.GetMothsCategory(this.StartDate, this.EndDate);

            double times = this.EndDate.Subtract(this.StartDate).TotalDays + 1;
            this.pbarSimulation.Maximum = (int)times;

            for (int i = 0; i < times; i++)
            {
                _valuesDemandBanana.Add(0);
                _valuesDemandCarrot.Add(0);
                _valuesDemandGrapefruit.Add(0);
                _valuesDemandLemon.Add(0);
                _valuesDemandMelon.Add(0);
                _valuesDemandNopal.Add(0);
                _valuesDemandOrange.Add(0);
                _valuesDemandPerejil.Add(0);
                _valuesDemandGuayaba.Add(0);
                _valuesDemandMango.Add(0);
                _valuesDemandPineapple.Add(0);
                _valuesDemandStrawberry.Add(0);

                _valuesInventaryBanana.Add(0);
                _valuesInventaryCarrot.Add(0);
                _valuesInventaryGrapefruit.Add(0);
                _valuesInventaryLemon.Add(0);
                _valuesInventaryMelon.Add(0);
                _valuesInventaryNopal.Add(0);
                _valuesInventaryOrange.Add(0);
                _valuesInventaryPerejil.Add(0);
                _valuesInventaryGuayaba.Add(0);
                _valuesInventaryMango.Add(0);
                _valuesInventaryPineapple.Add(0);
                _valuesInventaryStrawberry.Add(0);
            }

            DateTime currentDate = this.StartDate;

            for (int i = 0; i < times; i++)
            {
                this.GetInventary(i);
                this.GetDemand(currentDate, i);

                currentDate = currentDate.AddDays(1);


                this.pbarSimulation.PerformStep();
            }

            this.CreateOutputDataSource();

            this.cbFruit.Enabled = true;
            this.pbarSimulation.Visible = false;
        }

        /// <summary>
        /// Gets a <see cref="List"/> of months used by the Chart.
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns><example>"",Julio, "","","",Agosto,""</example></returns>
        private List<string> GetMothsCategory(DateTime startDate, DateTime endDate)
        {
            double totalDays = this.EndDate.Subtract(this.StartDate).TotalDays + 1;

            List<string> monthsList = new List<string>();

            DateTime currentDate = startDate.AddDays(6);  //First suday
            DateTime lastDate = currentDate;

            for (int i = 0; i < totalDays; i++)
            {
                monthsList.Add("");
                currentDate = currentDate.AddDays(1);
                int month = lastDate.Month;
                if (currentDate.Month != lastDate.Month)
                {
                    monthsList.RemoveAt(monthsList.Count - 1);
                    monthsList.Add(this.GetMonthString(month));
                    lastDate = currentDate;
                }
            }

            if (monthsList.Count < 3)
            {
                int month = lastDate.Month;
                monthsList.RemoveAt(monthsList.Count - 1);
                monthsList.Add(this.GetMonthString(month));
            }

            return monthsList;
        }

        /// <summary>
        /// Gets the string of the specified month.
        /// </summary>
        /// <param name="month">Number of month.</param>
        /// <returns>String of the month.</returns>
        private string GetMonthString(int month)
        {
            switch (month)
            {
                case 1:
                    return "Enero";
                case 2:
                    return "Febrero";
                case 3:
                    return "Marzo";
                case 4:
                    return "Abril";
                case 5:
                    return "Mayo";
                case 6:
                    return "Junio";
                case 7:
                    return "Julio";
                case 8:
                    return "Agosto";
                case 9:
                    return "Septiembre";
                case 10:
                    return "Octubre";
                case 11:
                    return "Noviembre";
                case 12:
                    return "Diciembre";
                default:
                    return "";
            }
        }

        private void CreateOutputDataSource()
        {
            this._outputDataSet = new DataSet();
            DataTable outputTable = new DataTable("Output");
            outputTable.Columns.Add("Fruta", typeof(string));
            outputTable.Columns.Add("NDOA", typeof(int));
            outputTable.Columns.Add("NDKA", typeof(string));
            outputTable.Columns.Add("NDKPC", typeof(string));
            outputTable.Columns.Add("CT", typeof(string));

            this._outputDataSet.Tables.Add(outputTable);

            this.AddOutputRow(Fruit.Plátano.ToString(), this._banana.NDOA, this._banana.NDKA.ToString("0.00", CultureInfo.InvariantCulture), this._banana.DeadProduct.ToString("0.00", CultureInfo.InvariantCulture), this._banana.CTF.ToString("C"));
            this.AddOutputRow(Fruit.Zanahoria.ToString(), this._carrot.NDOA, this._carrot.NDKA.ToString("0.00", CultureInfo.InvariantCulture), this._carrot.DeadProduct.ToString("0.00", CultureInfo.InvariantCulture), this._carrot.CTF.ToString("C"));
            this.AddOutputRow(Fruit.Toronja.ToString(), this._grapefruit.NDOA, this._grapefruit.NDKA.ToString("0.00", CultureInfo.InvariantCulture), this._grapefruit.DeadProduct.ToString("0.00", CultureInfo.InvariantCulture), this._grapefruit.CTF.ToString("C"));
            this.AddOutputRow(Fruit.Limón.ToString(), this._lemon.NDOA, this._lemon.NDKA.ToString("0.00", CultureInfo.InvariantCulture), this._lemon.DeadProduct.ToString("0.00", CultureInfo.InvariantCulture), this._lemon.CTF.ToString("C"));
            this.AddOutputRow(Fruit.Melón.ToString(), this._melon.NDOA, this._melon.NDKA.ToString("0.00", CultureInfo.InvariantCulture), this._melon.DeadProduct.ToString("0.00", CultureInfo.InvariantCulture), this._melon.CTF.ToString("C"));
            this.AddOutputRow(Fruit.Nopal.ToString(), this._nopal.NDOA, this._nopal.NDKA.ToString("0.00", CultureInfo.InvariantCulture), this._nopal.DeadProduct.ToString("0.00", CultureInfo.InvariantCulture), this._nopal.CTF.ToString("C"));
            this.AddOutputRow(Fruit.Naranja.ToString(), this._orange.NDOA, this._orange.NDKA.ToString("0.00", CultureInfo.InvariantCulture), this._orange.DeadProduct.ToString("0.00", CultureInfo.InvariantCulture), this._orange.CTF.ToString("C"));
            this.AddOutputRow(Fruit.Perejil.ToString(), this._perejil.NDOA, this._perejil.NDKA.ToString("0.00", CultureInfo.InvariantCulture), this._perejil.DeadProduct.ToString("0.00", CultureInfo.InvariantCulture), this._perejil.CTF.ToString("C"));
            this.AddOutputRow(Fruit.Guayaba.ToString(), this._guayaba.NDOA, this._guayaba.NDKA.ToString("0.00", CultureInfo.InvariantCulture), this._guayaba.DeadProduct.ToString("0.00", CultureInfo.InvariantCulture), this._guayaba.CTF.ToString("C"));
            this.AddOutputRow(Fruit.Mango.ToString(), this._mango.NDOA, this._mango.NDKA.ToString("0.00", CultureInfo.InvariantCulture), this._mango.DeadProduct.ToString("0.00", CultureInfo.InvariantCulture), this._mango.CTF.ToString("C"));
            this.AddOutputRow(Fruit.Piña.ToString(), this._pineapple.NDOA, this._pineapple.NDKA.ToString("0.00", CultureInfo.InvariantCulture), this._pineapple.DeadProduct.ToString("0.00", CultureInfo.InvariantCulture), this._pineapple.CTF.ToString("C"));
            this.AddOutputRow(Fruit.Fresa.ToString(), this._strawberry.NDOA, this._strawberry.NDKA.ToString("0.00", CultureInfo.InvariantCulture), this._strawberry.DeadProduct.ToString("0.00", CultureInfo.InvariantCulture), this._strawberry.CTF.ToString("C"));

            int NDOA = this._banana.NDOA + this._carrot.NDOA + this._grapefruit.NDOA + this._lemon.NDOA + this._melon.NDOA + this._nopal.NDOA + this._orange.NDOA + this._perejil.NDOA + this._guayaba.NDOA + this._mango.NDOA + this._pineapple.NDOA + this._strawberry.NDOA;
            double NDKA = this._banana.NDKA + this._carrot.NDKA + this._grapefruit.NDKA + this._lemon.NDKA + this._melon.NDKA + this._nopal.NDKA + this._orange.NDKA + this._perejil.NDKA + this._guayaba.NDKA + this._mango.NDKA + this._pineapple.NDKA + this._strawberry.NDKA;
            double DeadProduct = this._banana.DeadProduct + this._carrot.DeadProduct + this._grapefruit.DeadProduct + this._lemon.DeadProduct + this._melon.DeadProduct + this._nopal.DeadProduct + this._orange.DeadProduct + this._perejil.DeadProduct + this._guayaba.DeadProduct + this._mango.DeadProduct + this._pineapple.DeadProduct + this._strawberry.DeadProduct;
            double CTF = this._banana.CTF + this._carrot.CTF + this._grapefruit.CTF + this._lemon.CTF + this._melon.CTF + this._nopal.CTF + this._orange.CTF + this._perejil.CTF + this._guayaba.CTF + this._mango.CTF + this._pineapple.CTF + this._strawberry.CTF;

            this.AddOutputRow("Totales", NDOA, NDKA.ToString("0.00", CultureInfo.InvariantCulture), DeadProduct.ToString("0.00", CultureInfo.InvariantCulture), CTF.ToString("C"));

            this.dgCaducado.DataSource = this._outputDataSet.Tables["Output"];

            this.dgCaducado.Rows[this.dgCaducado.Rows.Count - 2].Selected = true;
        }

        /// <summary>
        /// Creates the Order dataset to storage the orders.
        /// </summary>
        private void CreateOrderDataSet()
        {
            _dsOrders = new DataSet();
            DataTable orderTable = new DataTable("Orders");
            orderTable.Columns.Add("Fruta", typeof(string));
            orderTable.Columns.Add("Cantidad", typeof(double));
            orderTable.Columns.Add("Dia", typeof(string));

            this._dsOrders.Tables.Add(orderTable);

            // Miercoles
            this.AgregarFrutaOrdenFija(Fruit.Naranja, 100, Day.Miercoles);
            this.AgregarFrutaOrdenFija(Fruit.Plátano, 12, Day.Miercoles);
            this.AgregarFrutaOrdenFija(Fruit.Melón, 2, Day.Miercoles);
            this.AgregarFrutaOrdenFija(Fruit.Toronja, 19, Day.Miercoles);
            this.AgregarFrutaOrdenFija(Fruit.Fresa, 5, Day.Miercoles);
            this.AgregarFrutaOrdenFija(Fruit.Piña, 7.5, Day.Miercoles);
            this.AgregarFrutaOrdenFija(Fruit.Guayaba, 0.5, Day.Miercoles);
            this.AgregarFrutaOrdenFija(Fruit.Mango, 3, Day.Miercoles);
            this.AgregarFrutaOrdenFija(Fruit.Zanahoria, 8.5, Day.Miercoles);
            this.AgregarFrutaOrdenFija(Fruit.Limón, 0.4, Day.Miercoles);
            this.AgregarFrutaOrdenFija(Fruit.Perejil, 0.1, Day.Miercoles);
            this.AgregarFrutaOrdenFija(Fruit.Nopal, 1, Day.Miercoles);

            // Sabado
            this.AgregarFrutaOrdenFija(Fruit.Naranja, 140, Day.Sabado);
            this.AgregarFrutaOrdenFija(Fruit.Plátano, 16, Day.Sabado);
            this.AgregarFrutaOrdenFija(Fruit.Melón, 2.5, Day.Sabado);
            this.AgregarFrutaOrdenFija(Fruit.Toronja, 26, Day.Sabado);
            this.AgregarFrutaOrdenFija(Fruit.Fresa, 7, Day.Sabado);
            this.AgregarFrutaOrdenFija(Fruit.Piña, 10, Day.Sabado);
            this.AgregarFrutaOrdenFija(Fruit.Guayaba, 0.7, Day.Sabado);
            this.AgregarFrutaOrdenFija(Fruit.Mango, 4, Day.Sabado);
            this.AgregarFrutaOrdenFija(Fruit.Zanahoria, 11.5, Day.Sabado);
            this.AgregarFrutaOrdenFija(Fruit.Limón, 0.6, Day.Sabado);
            this.AgregarFrutaOrdenFija(Fruit.Perejil, 0.1, Day.Sabado);
            this.AgregarFrutaOrdenFija(Fruit.Nopal, 1.25, Day.Sabado);
            

            this.dgvOrders.DataSource = this._dsOrders.Tables["Orders"];
        }

        private void CreatesInitialInventary()
        {
            this._initialInventary = new DataSet();
            DataTable inventaryTable = new DataTable("Inventary");
            inventaryTable.Columns.Add("Fruta", typeof(string));
            inventaryTable.Columns.Add("Cantidad", typeof(double));
            inventaryTable.Columns.Add("Dia", typeof(DateTime));
            inventaryTable.Columns.Add("Precio mayoreo", typeof(double));
            inventaryTable.Columns.Add("Precio menudeo", typeof(double));

            this._initialInventary.Tables.Add(inventaryTable);

            
            
            

            this.AddInitialInventaryRow(Fruit.Naranja, 100, System.DateTime.Today, 10, 20);
            this.AddInitialInventaryRow(Fruit.Plátano, 12, System.DateTime.Today, 12, 17);
            this.AddInitialInventaryRow(Fruit.Melón, 2, System.DateTime.Today, 9, 14);
            this.AddInitialInventaryRow(Fruit.Toronja, 19, System.DateTime.Today, 7, 11);
            this.AddInitialInventaryRow(Fruit.Fresa, 5, System.DateTime.Today, 45, 70);
            this.AddInitialInventaryRow(Fruit.Piña, 7.5, System.DateTime.Today, 12, 19);
            this.AddInitialInventaryRow(Fruit.Guayaba, 0.5, System.DateTime.Today, 9, 20);
            this.AddInitialInventaryRow(Fruit.Mango, 3, System.DateTime.Today, 20, 27);
            this.AddInitialInventaryRow(Fruit.Zanahoria, 8.5, System.DateTime.Today, 6, 10);
            this.AddInitialInventaryRow(Fruit.Limón, 0.4, System.DateTime.Today, 9, 12);
            this.AddInitialInventaryRow(Fruit.Perejil, 0.1, System.DateTime.Today, 5, 8);
            this.AddInitialInventaryRow(Fruit.Nopal, 1, System.DateTime.Today, 14, 22);

            this.dgvInitialInvenary.DataSource = this._initialInventary.Tables["Inventary"];
        }

        /// <summary>
        /// Add the selected fruit to the DataSet.
        /// </summary>
        /// <param name="fruta">Name of the fruit.</param>
        /// <param name="cantidad">Quantity in Kg.</param>
        /// <param name="dia"><see cref="Day"/> the fruit is bought.</param>
        private void AgregarFrutaOrdenFija(Fruit fruta, double cantidad, Day dia)
        {
            DataRow drFruta = this._dsOrders.Tables["Orders"].NewRow();
            drFruta["Fruta"] = fruta;
            drFruta["Cantidad"] = cantidad;
            drFruta["Dia"] = dia;

            _dsOrders.Tables[0].Rows.Add(drFruta);
        }

        private void AddOutputRow(string fruta, int NDOA, string NDKA, string NDKPC, string TC)
        {
            DataRow drFruta = this._outputDataSet.Tables["Output"].NewRow();
            drFruta["Fruta"] = fruta;
            drFruta["NDOA"] = NDOA;
            drFruta["NDKA"] = NDKA;
            drFruta["NDKPC"] = NDKPC;
            drFruta["CT"] = TC;

            _outputDataSet.Tables[0].Rows.Add(drFruta);
        }

        /// <summary>
        /// Adds the default initial inventary to the <see cref="_initialInventary"/> dataset.
        /// </summary>
        /// <param name="fruta"></param>
        /// <param name="cantidad"></param>
        /// <param name="date"></param>
        /// <param name="precioMayoreo">Whole price.</param>
        /// <param name="precioMenudeo">Retail price.</param>
        private void AddInitialInventaryRow(Fruit fruta, double cantidad, DateTime date, double precioMayoreo, double precioMenudeo)
        {
            DataRow drFruta = this._initialInventary.Tables["Inventary"].NewRow();
            drFruta["Fruta"] = fruta;
            drFruta["Cantidad"] = cantidad;
            drFruta["Dia"] = date;
            drFruta["Precio mayoreo"] = precioMayoreo;
            drFruta["Precio menudeo"] = precioMenudeo;

            this._initialInventary.Tables[0].Rows.Add(drFruta);
        }

        /// <summary>
        /// Adds the initial inventary to the fruits.
        /// </summary>
        private void AddInitialInventaryFruits()
        {
            foreach (DataRow drFruit in this._initialInventary.Tables["Inventary"].Rows)
            {
                string fruit = drFruit["Fruta"].ToString();
                double cantidad = (double)drFruit["Cantidad"];
                double precioMayoreo = (double)drFruit["Precio mayoreo"];
                double precioMenudeo = (double)drFruit["Precio menudeo"];

                if (fruit == Fruit.Naranja.ToString())
                {
                    this._orange.AddInventary = cantidad;
                    this._orange.WholeSPrice = precioMayoreo;
                    this._orange.RetailPrice = precioMenudeo;
                }
                else if (fruit == Fruit.Plátano.ToString())
                {
                    this._banana.AddInventary = cantidad;
                    this._banana.WholeSPrice = precioMayoreo;
                    this._banana.RetailPrice = precioMenudeo;
                }
                else if (fruit == Fruit.Melón.ToString())
                {
                    this._melon.AddInventary = cantidad;
                    this._melon.WholeSPrice = precioMayoreo;
                    this._melon.RetailPrice = precioMenudeo;
                }
                else if (fruit == Fruit.Toronja.ToString())
                {
                    this._grapefruit.AddInventary = cantidad;
                    this._grapefruit.WholeSPrice = precioMayoreo;
                    this._grapefruit.RetailPrice = precioMenudeo;
                }
                else if (fruit == Fruit.Fresa.ToString())
                {
                    this._strawberry.AddInventary = cantidad;
                    this._strawberry.WholeSPrice = precioMayoreo;
                    this._strawberry.RetailPrice = precioMenudeo;

                }
                else if (fruit == Fruit.Piña.ToString())
                {
                    this._pineapple.AddInventary = cantidad;
                    this._pineapple.WholeSPrice = precioMayoreo;
                    this._pineapple.RetailPrice = precioMenudeo;
                }
                else if (fruit == Fruit.Guayaba.ToString())
                {
                    this._guayaba.AddInventary = cantidad;
                    this._guayaba.WholeSPrice = precioMayoreo;
                    this._guayaba.RetailPrice = precioMenudeo;
                }
                else if (fruit == Fruit.Mango.ToString())
                {
                    this._mango.AddInventary = cantidad;
                    this._mango.WholeSPrice = precioMayoreo;
                    this._mango.RetailPrice = precioMenudeo;
                }
                else if (fruit == Fruit.Zanahoria.ToString())
                {
                    this._carrot.AddInventary = cantidad;
                    this._carrot.WholeSPrice = precioMayoreo;
                    this._carrot.RetailPrice = precioMenudeo;
                }
                else if (fruit == Fruit.Limón.ToString())
                {
                    this._lemon.AddInventary = cantidad;
                    this._lemon.WholeSPrice = precioMayoreo;
                    this._lemon.RetailPrice = precioMenudeo;
                }
                else if (fruit == Fruit.Perejil.ToString())
                {
                    this._perejil.AddInventary = cantidad;
                    this._perejil.WholeSPrice = precioMayoreo;
                    this._perejil.RetailPrice = precioMenudeo;
                }
                else if (fruit == Fruit.Nopal.ToString())
                {
                    this._nopal.AddInventary = cantidad;
                    this._nopal.WholeSPrice = precioMayoreo;
                    this._nopal.RetailPrice = precioMenudeo;
                }
            }
        }

        private void GetOrderInformation()
        {
            foreach (DataRow drFruit in this._dsOrders.Tables["Orders"].Rows)
            {
                if (drFruit["Fruta"].ToString() == Fruit.Naranja.ToString())
                {
                    DataRow dr = this._orange.Orders.NewRow();
                    dr["Cantidad"] = drFruit["Cantidad"];
                    dr["Dia"] = drFruit["Dia"];
                    this._orange.Orders.Rows.Add(dr);
                }
                else if (drFruit["Fruta"].ToString() == Fruit.Plátano.ToString())
                {
                    DataRow dr = this._banana.Orders.NewRow();
                    dr["Cantidad"] = drFruit["Cantidad"];
                    dr["Dia"] = drFruit["Dia"];
                    this._banana.Orders.Rows.Add(dr);
                }
                else if (drFruit["Fruta"].ToString() == Fruit.Melón.ToString())
                {
                    DataRow dr = this._melon.Orders.NewRow();
                    dr["Cantidad"] = drFruit["Cantidad"];
                    dr["Dia"] = drFruit["Dia"];
                    this._melon.Orders.Rows.Add(dr);
                }
                else if (drFruit["Fruta"].ToString() == Fruit.Toronja.ToString())
                {
                    DataRow dr = this._grapefruit.Orders.NewRow();
                    dr["Cantidad"] = drFruit["Cantidad"];
                    dr["Dia"] = drFruit["Dia"];
                    this._grapefruit.Orders.Rows.Add(dr);
                }
                else if (drFruit["Fruta"].ToString() == Fruit.Zanahoria.ToString())
                {
                    DataRow dr = this._carrot.Orders.NewRow();
                    dr["Cantidad"] = drFruit["Cantidad"];
                    dr["Dia"] = drFruit["Dia"];
                    this._carrot.Orders.Rows.Add(dr);
                }
                else if (drFruit["Fruta"].ToString() == Fruit.Limón.ToString())
                {
                    DataRow dr = this._lemon.Orders.NewRow();
                    dr["Cantidad"] = drFruit["Cantidad"];
                    dr["Dia"] = drFruit["Dia"];
                    this._lemon.Orders.Rows.Add(dr);
                }
                else if (drFruit["Fruta"].ToString() == Fruit.Perejil.ToString())
                {
                    DataRow dr = this._perejil.Orders.NewRow();
                    dr["Cantidad"] = drFruit["Cantidad"];
                    dr["Dia"] = drFruit["Dia"];
                    this._perejil.Orders.Rows.Add(dr);
                }
                else if (drFruit["Fruta"].ToString() == Fruit.Nopal.ToString())
                {
                    DataRow dr = this._nopal.Orders.NewRow();
                    dr["Cantidad"] = drFruit["Cantidad"];
                    dr["Dia"] = drFruit["Dia"];
                    this._nopal.Orders.Rows.Add(dr);
                }
                else if (drFruit["Fruta"].ToString() == Fruit.Mango.ToString())
                {
                    DataRow dr = this._mango.Orders.NewRow();
                    dr["Cantidad"] = drFruit["Cantidad"];
                    dr["Dia"] = drFruit["Dia"];
                    this._mango.Orders.Rows.Add(dr);
                }
                else if (drFruit["Fruta"].ToString() == Fruit.Guayaba.ToString())
                {
                    DataRow dr = this._guayaba.Orders.NewRow();
                    dr["Cantidad"] = drFruit["Cantidad"];
                    dr["Dia"] = drFruit["Dia"];
                    this._guayaba.Orders.Rows.Add(dr);
                }
                else if (drFruit["Fruta"].ToString() == Fruit.Piña.ToString())
                {
                    DataRow dr = this._pineapple.Orders.NewRow();
                    dr["Cantidad"] = drFruit["Cantidad"];
                    dr["Dia"] = drFruit["Dia"];
                    this._pineapple.Orders.Rows.Add(dr);
                }
                else if (drFruit["Fruta"].ToString() == Fruit.Fresa.ToString())
                {
                    DataRow dr = this._strawberry.Orders.NewRow();
                    dr["Cantidad"] = drFruit["Cantidad"];
                    dr["Dia"] = drFruit["Dia"];
                    this._strawberry.Orders.Rows.Add(dr);
                }
            }
        }

        private void GenerateDistributionChart()
        {
            string fruit = this.cbFruitDistr.Text;

            if (fruit == Fruit.Naranja.ToString())
            {
                DrawDistrFruitChart(Fruit.Naranja.ToString(), _orange);
            }
            else if (fruit == Fruit.Plátano.ToString())
            {
                DrawDistrFruitChart(Fruit.Plátano.ToString(), _banana);
            }
            else if (fruit == Fruit.Melón.ToString())
            {
                DrawDistrFruitChart(Fruit.Melón.ToString(), this._melon);
            }
            else if (fruit == Fruit.Toronja.ToString())
            {
                DrawDistrFruitChart(Fruit.Toronja.ToString(), this._grapefruit);
            }
            else if (fruit == Fruit.Fresa.ToString())
            {
                DrawDistrFruitChart(Fruit.Fresa.ToString(), this._strawberry);
            }
            else if (fruit == Fruit.Piña.ToString())
            {
                DrawDistrFruitChart(Fruit.Piña.ToString(), this._pineapple);
            }
            else if (fruit == Fruit.Guayaba.ToString())
            {
                DrawDistrFruitChart(Fruit.Guayaba.ToString(), this._guayaba);
            }
            else if (fruit == Fruit.Mango.ToString())
            {
                DrawDistrFruitChart(Fruit.Mango.ToString(), this._mango);
            }
            else if (fruit == Fruit.Zanahoria.ToString())
            {
                DrawDistrFruitChart(Fruit.Zanahoria.ToString(), this._carrot);
            }
            else if (fruit == Fruit.Limón.ToString())
            {
                DrawDistrFruitChart(Fruit.Limón.ToString(), this._lemon);
            }
            else if (fruit == Fruit.Perejil.ToString())
            {
                DrawDistrFruitChart(Fruit.Perejil.ToString(), this._perejil);
            }
            else if (fruit == Fruit.Nopal.ToString())
            {
                DrawDistrFruitChart(Fruit.Nopal.ToString(), this._nopal);
            }
        }

        private void GenerateOutputChart()
        {
            string fruit = this.cbFruit.Text;

            if (fruit == Fruit.Naranja.ToString())
            {
                this.DrawOutputChart(Fruit.Naranja.ToString(), _orange);
            }
            else if (fruit == Fruit.Plátano.ToString())
            {
                this.DrawOutputChart(Fruit.Plátano.ToString(), _banana);
            }
            else if (fruit == Fruit.Melón.ToString())
            {
                this.DrawOutputChart(Fruit.Melón.ToString(), this._melon);
            }
            else if (fruit == Fruit.Toronja.ToString())
            {
                this.DrawOutputChart(Fruit.Toronja.ToString(), this._grapefruit);
            }
            else if (fruit == Fruit.Fresa.ToString())
            {
                this.DrawOutputChart(Fruit.Fresa.ToString(), this._strawberry);
            }
            else if (fruit == Fruit.Piña.ToString())
            {
                this.DrawOutputChart(Fruit.Piña.ToString(), this._pineapple);
            }
            else if (fruit == Fruit.Guayaba.ToString())
            {
                this.DrawOutputChart(Fruit.Guayaba.ToString(), this._guayaba);
            }
            else if (fruit == Fruit.Mango.ToString())
            {
                this.DrawOutputChart(Fruit.Mango.ToString(), this._mango);
            }
            else if (fruit == Fruit.Zanahoria.ToString())
            {
                this.DrawOutputChart(Fruit.Zanahoria.ToString(), this._carrot);
            }
            else if (fruit == Fruit.Limón.ToString())
            {
                this.DrawOutputChart(Fruit.Limón.ToString(), this._lemon);
            }
            else if (fruit == Fruit.Perejil.ToString())
            {
                this.DrawOutputChart(Fruit.Perejil.ToString(), this._perejil);
            }
            else if (fruit == Fruit.Nopal.ToString())
            {
                this.DrawOutputChart(Fruit.Nopal.ToString(), this._nopal);
            }
        }

        #endregion Private Methods

        #region Public Properties

        DateTime StartDate
        {
            get
            {
                return this.dtPickerStartDate.Value;
            }
        }

        DateTime EndDate
        {
            get
            {
                return this.dtPickerEndDate.Value;
            }
        }

        public double CostoOrdenFijo
        {
            get
            {
                return Convert.ToDouble(this.txtCostoOrdenarFijo.Text);
            }
        }

        public double CostoMantener
        {
            get
            {
                return Convert.ToDouble(this.txtCostoMantener.Text);
            }
        }

        public double CostoAgotado
        {
            get
            {
                return Convert.ToDouble(this.txtCostoAgotado.Text);
            }
        }

        public double CostoExtraordinario
        {
            get
            {
                return Convert.ToDouble(this.txtCostoExtraordinario.Text);
            }
        }

        #endregion Public Properties

        #region Public Methods

        /// <summary>
        /// Draw the chart for the specified fruit.
        /// </summary>
        /// <param name="title">The title of the chart. Example: <example>Naranja</example>.</param>
        /// <param name="valuesDemandDataSource">DataSource values of the demand.</param>
        /// <param name="categoryNamesDDataSource">DataSource categories.</param>
        /// <param name="valuesInventaryDataSource">DataSourc of the inventary.</param>
        /// <param name="smoothedLine"></param>
        public void DrawFruitChart(string title, List<double> valuesDemandDataSource, List<double> valuesInventaryDataSource, List<string> categoryNamesDDataSource, bool smoothedLine, int length)
        {
            List<double> demandValues = new List<double>(length);
            List<double> inventaryValues = new List<double>(length);
            for (int i = 0; i < length; i++)
            {
                demandValues.Add(0);
                inventaryValues.Add(0);
            }

            this.pbarSimulation.Maximum = (int)length;
            this.pbarSimulation.Step = 1;
            this.pbarSimulation.Visible = true;
            this.pbarSimulation.Value = 0;

            for (int j = 0; j < length; j++)
            {
                demandValues[j] = valuesDemandDataSource[j];
                inventaryValues[j] = valuesInventaryDataSource[j];

                LineSeries lineSeriesDemand = new LineSeries();
                lineSeriesDemand.SmoothedLine = smoothedLine;
                lineSeriesDemand.Values.DataSource = demandValues;
                lineSeriesDemand.CategoryNames.DataSource = categoryNamesDDataSource;
                lineSeriesDemand.SeriesName = "Demanda";

                LineSeries lineSeriesInventary = new LineSeries();
                lineSeriesInventary.SmoothedLine = smoothedLine;
                lineSeriesInventary.Values.DataSource = inventaryValues;
                lineSeriesInventary.CategoryNames.DataSource = categoryNamesDDataSource;
                lineSeriesInventary.SeriesName = "Inventario";

                FarPoint.Win.Chart.YPlotArea plotArea = new FarPoint.Win.Chart.YPlotArea();
                FarPoint.Win.Chart.ChartModel model = new FarPoint.Win.Chart.ChartModel();

                plotArea.Location = new PointF(0.1F, 0.1F);
                plotArea.Size = new SizeF(0.8F, 0.8F);
                plotArea.XAxis.Title = "Meses";
                plotArea.YAxes[0].Title = "Kg.";
                plotArea.Series.Add(lineSeriesDemand);
                plotArea.Series.Add(lineSeriesInventary);

                model.PlotAreas.Add(plotArea);

                LabelArea labelArea = new LabelArea();
                labelArea.Text = title;
                labelArea.Location = new PointF(0.5F, 0.01F);

                model.LabelAreas.Add(labelArea);
                fpChartFruit.Model = model;

                this.pbarSimulation.PerformStep();
                System.Threading.Thread.Sleep((int)this.nudThreadTime.Value);
                this.fpChartFruit.Refresh();
            }
        }

        /// <summary>
        /// Draw the chart for the specified fruit.
        /// </summary>
        public void DrawDistrFruitChart(string fruitName, Fruits.Fruit pFruit)
        {
            if (pFruit != null)
            {
                DateTime aDay = new DateTime(2010, 11, 1); // November first
                if (this.cbPeriodo.SelectedIndex == 1) aDay = new DateTime(2010, 7, 1); // July first
                if (this.cbPeriodo.SelectedIndex == 2) aDay = new DateTime(2010, 4, 1); // April first

                List<double> xp = new List<double>();
                List<double> yp = new List<double>();

                for (int i = 0; i < 100; i++)
                {
                    double aDemand = pFruit.GenerateDemand(aDay) * 7;
                    xp.Add(aDemand);
                    yp.Add(pFruit.GenerateF(aDay, aDemand));
                }

                XYPointSeries puntos = new XYPointSeries();
                puntos.XValues.DataSource = xp;
                puntos.YValues.DataSource = yp;
                puntos.SeriesName = "Demanda";

                FarPoint.Win.Chart.XYPlotArea plotArea = new FarPoint.Win.Chart.XYPlotArea();
                FarPoint.Win.Chart.ChartModel model = new FarPoint.Win.Chart.ChartModel();

                plotArea.Location = new PointF(0.15F, 0.15F);
                plotArea.Size = new SizeF(0.7F, 0.7F);
                plotArea.XAxes[0].AutoMaximum = false;
                plotArea.XAxes[0].AutoMinimum = false;
                plotArea.XAxes[0].Maximum = pFruit.getMaxLimit(aDay);
                plotArea.XAxes[0].Minimum = pFruit.getMinLimit(aDay);
                plotArea.XAxes[0].TitleOffset = 20;
                plotArea.XAxes[0].Title = "Kilogramos de " + fruitName;
                plotArea.YAxes[0].LabelVisible = false;

                plotArea.Series.Add(puntos);

                model.PlotAreas.Add(plotArea);

                LabelArea titleLabel = new LabelArea();
                titleLabel.Text = "Distribuciones";
                titleLabel.Location = new PointF(0.5F, 0.05F);
                titleLabel.AlignmentX = 0.5F;
                titleLabel.AlignmentY = 0.0F;

                model.LabelAreas.Add(titleLabel);
                fpDistrChart.Model = model;
            }
        }

        public void DrawOutputChart(string fruitName, Fruits.Fruit fruit)
        {
            this.fpChartOutput.Refresh();

            BarSeries barSeries = new BarSeries();
            barSeries.VaryColors = true;
            barSeries.LabelVisible = true;
            barSeries.Values.Add(fruit.NDKA);
            barSeries.Values.Add(fruit.DeadProduct);
            barSeries.Values.Add(fruit.NDOA);
            barSeries.Values.Add(fruit.NDOPC);

            barSeries.LabelNumberFormat = "#,##0.00";

            barSeries.CategoryNames.Add("NDKA");
            barSeries.CategoryNames.Add("NDKPC");
            barSeries.CategoryNames.Add("NDOA");
            barSeries.CategoryNames.Add("NDOPC");
            barSeries.SeriesName = "Output";

            FarPoint.Win.Chart.YPlotArea plotArea = new FarPoint.Win.Chart.YPlotArea();
            FarPoint.Win.Chart.ChartModel model = new FarPoint.Win.Chart.ChartModel();

            plotArea.Location = new PointF(0.15F, 0.15F);
            plotArea.Size = new SizeF(0.7F, 0.7F);

            plotArea.Series.Add(barSeries);

            model.PlotAreas.Add(plotArea);

            LabelArea titleLabel = new LabelArea();
            titleLabel.Text = "Salidas";
            titleLabel.Location = new PointF(0.5F, 0.05F);
            titleLabel.AlignmentX = 0.5F;
            titleLabel.AlignmentY = 0.0F;

            model.LabelAreas.Add(titleLabel);
            this.fpChartOutput.Model = model;
        }

        #endregion Public Methods

        #region Event Handlers

        /// <summary>
        /// Changes the StartDate by Monday of the selected week.
        /// </summary>
        /// <example>If the selected date is Wednesday, it changes the start date by Monday of that week.</example>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dtPickerStartDate_ValueChanged(object sender, EventArgs e)
        {
            if (dtPickerStartDate.Value.DayOfWeek != DayOfWeek.Monday)
            {
                switch (dtPickerStartDate.Value.DayOfWeek)
                {
                    case DayOfWeek.Tuesday:
                        this.dtPickerStartDate.Value = this.StartDate.AddDays(-1);
                        break;
                    case DayOfWeek.Wednesday:
                        this.dtPickerStartDate.Value = this.StartDate.AddDays(-2);
                        break;
                    case DayOfWeek.Thursday:
                        this.dtPickerStartDate.Value = this.StartDate.AddDays(-3);
                        break;
                    case DayOfWeek.Friday:
                        this.dtPickerStartDate.Value = this.StartDate.AddDays(-4);
                        break;
                    case DayOfWeek.Saturday:
                        this.dtPickerStartDate.Value = this.StartDate.AddDays(-5);
                        break;
                    case DayOfWeek.Sunday:
                        this.dtPickerStartDate.Value = this.StartDate.AddDays(-6);
                        break;
                }
            }

        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            this.CreateOrderDataSet();
            this.CreatesInitialInventary();

            this.dtPickerStartDate.Value = new DateTime(System.DateTime.Now.AddMonths(1).Year, System.DateTime.Now.AddMonths(1).Month, System.DateTime.DaysInMonth(this.StartDate.Year, System.DateTime.Now.AddMonths(1).Month) - this.StartDate.Day);
            this.dtPickerEndDate.Value = new DateTime(System.DateTime.Now.AddMonths(1).Year, System.DateTime.Now.AddMonths(1).Month, System.DateTime.DaysInMonth(this.StartDate.Year, System.DateTime.Now.AddMonths(1).Month) - this.EndDate.Day + 7);
        }

        /// <summary>
        /// Changes the EndDate by Sunday of the selected week.
        /// </summary>
        /// <example>If the selected date is Wednesday, it changes the end date by Sunday of that week.</example>
        private void dtPickerEndDate_ValueChanged(object sender, EventArgs e)
        {
            if (dtPickerEndDate.Value.DayOfWeek != DayOfWeek.Sunday)
            {
                switch (dtPickerEndDate.Value.DayOfWeek)
                {
                    case DayOfWeek.Monday:
                        this.dtPickerEndDate.Value = this.EndDate.AddDays(6);
                        break;
                    case DayOfWeek.Tuesday:
                        this.dtPickerEndDate.Value = this.EndDate.AddDays(5);
                        break;
                    case DayOfWeek.Wednesday:
                        this.dtPickerEndDate.Value = this.EndDate.AddDays(4);
                        break;
                    case DayOfWeek.Thursday:
                        this.dtPickerEndDate.Value = this.EndDate.AddDays(3);
                        break;
                    case DayOfWeek.Friday:
                        this.dtPickerEndDate.Value = this.EndDate.AddDays(2);
                        break;
                    case DayOfWeek.Saturday:
                        this.dtPickerEndDate.Value = this.EndDate.AddDays(1);
                        break;
                }
            }
        }

        /// <summary>
        /// Run the method <see cref="RunSimulation"/>.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSimulate_Click(object sender, EventArgs e)
        {
            this.RunSimulation();
            if (this.cbFruit.SelectedIndex == 0)
            {
                this.cbFruit.SelectedIndex = 1;
            }
            else
            {
                this.cbFruit.SelectedIndex = 0;
            }
        }

        private void GetInventary(int i)
        {
            _valuesInventaryOrange[i] = this._orange.Inventary;
            _valuesInventaryBanana[i] = this._banana.Inventary;
            _valuesInventaryMelon[i] = this._melon.Inventary;
            _valuesInventaryGrapefruit[i] = this._grapefruit.Inventary;
            _valuesInventaryCarrot[i] = this._carrot.Inventary;
            _valuesInventaryLemon[i] = this._lemon.Inventary;
            _valuesInventaryPerejil[i] = this._perejil.Inventary;
            _valuesInventaryNopal[i] = this._nopal.Inventary;
            _valuesInventaryGuayaba[i] = this._guayaba.Inventary;
            _valuesInventaryMango[i] = this._mango.Inventary;
            _valuesInventaryPineapple[i] = this._pineapple.Inventary;
            _valuesInventaryStrawberry[i] = this._strawberry.Inventary;
        }

        private List<double> GetDemandList()
        {
            string fruit = this.cbFruit.Text;

            if (fruit == Fruit.Naranja.ToString())
            {
                return this._valuesDemandOrange;
            }
            else if (fruit == Fruit.Plátano.ToString())
            {
                return this._valuesDemandBanana;
            }
            else if (fruit == Fruit.Melón.ToString())
            {
                return this._valuesDemandMelon;
            }
            else if (fruit == Fruit.Toronja.ToString())
            {
                return this._valuesDemandGrapefruit;
            }
            else if (fruit == Fruit.Fresa.ToString())
            {
                return this._valuesDemandStrawberry;
            }
            else if (fruit == Fruit.Piña.ToString())
            {
                return this._valuesDemandPineapple;
            }
            else if (fruit == Fruit.Guayaba.ToString())
            {
                return this._valuesDemandGuayaba;
            }
            else if (fruit == Fruit.Mango.ToString())
            {
                return this._valuesDemandMango;
            }
            else if (fruit == Fruit.Zanahoria.ToString())
            {
                return this._valuesDemandCarrot;
            }
            else if (fruit == Fruit.Limón.ToString())
            {
                return this._valuesDemandLemon;
            }
            else if (fruit == Fruit.Perejil.ToString())
            {
                return this._valuesDemandPerejil;
            }
            else if (fruit == Fruit.Nopal.ToString())
            {
                return this._valuesDemandNopal;
            }

            return new List<double>(0);
        }


        private double GetCTF()
        {
            string fruit = this.cbFruit.Text;

            if (fruit == Fruit.Naranja.ToString())
            {
                return this._orange.CTF;
            }
            else if (fruit == Fruit.Plátano.ToString())
            {
                return this._banana.CTF;
            }
            else if (fruit == Fruit.Melón.ToString())
            {
                return this._melon.CTF;
            }
            else if (fruit == Fruit.Toronja.ToString())
            {
                return this._grapefruit.CTF;
            }
            else if (fruit == Fruit.Fresa.ToString())
            {
                return this._strawberry.CTF;
            }
            else if (fruit == Fruit.Piña.ToString())
            {
                return this._pineapple.CTF;
            }
            else if (fruit == Fruit.Guayaba.ToString())
            {
                return this._guayaba.CTF;
            }
            else if (fruit == Fruit.Mango.ToString())
            {
                return this._mango.CTF;
            }
            else if (fruit == Fruit.Zanahoria.ToString())
            {
                return this._carrot.CTF;
            }
            else if (fruit == Fruit.Limón.ToString())
            {
                return this._lemon.CTF;
            }
            else if (fruit == Fruit.Perejil.ToString())
            {
                return this._perejil.CTF;
            }
            else if (fruit == Fruit.Nopal.ToString())
            {
                return this._nopal.CTF;
            }

            return 0;
        }

        

        private List<double> GetInventaryList()
        {
            string fruit = this.cbFruit.Text;

            if (fruit == Fruit.Naranja.ToString())
            {
                return this._valuesInventaryOrange;
            }
            else if (fruit == Fruit.Plátano.ToString())
            {
                return this._valuesInventaryBanana;
            }
            else if (fruit == Fruit.Melón.ToString())
            {
                return this._valuesInventaryMelon;
            }
            else if (fruit == Fruit.Toronja.ToString())
            {
                return this._valuesInventaryGrapefruit;
            }
            else if (fruit == Fruit.Fresa.ToString())
            {
                return this._valuesInventaryStrawberry;
            }
            else if (fruit == Fruit.Piña.ToString())
            {
                return this._valuesInventaryPineapple;
            }
            else if (fruit == Fruit.Guayaba.ToString())
            {
                return this._valuesInventaryGuayaba;
            }
            else if (fruit == Fruit.Mango.ToString())
            {
                return this._valuesInventaryMango;
            }
            else if (fruit == Fruit.Zanahoria.ToString())
            {
                return this._valuesInventaryCarrot;
            }
            else if (fruit == Fruit.Limón.ToString())
            {
                return this._valuesInventaryLemon;
            }
            else if (fruit == Fruit.Perejil.ToString())
            {
                return this._valuesInventaryPerejil;
            }
            else if (fruit == Fruit.Nopal.ToString())
            {
                return this._valuesInventaryNopal;
            }

            return new List<double>(0);
        }

        private void GetDemand(DateTime date, int i)
        {
            _valuesDemandOrange[i] = this._orange.GetDemand(date);
            _valuesDemandBanana[i] = this._banana.GetDemand(date);
            _valuesDemandMelon[i] = this._melon.GetDemand(date);
            _valuesDemandGrapefruit[i] = this._grapefruit.GetDemand(date);
            _valuesDemandCarrot[i] = this._carrot.GetDemand(date);
            _valuesDemandLemon[i] = this._lemon.GetDemand(date);
            _valuesDemandMango[i] = this._mango.GetDemand(date);
            _valuesDemandPerejil[i] = this._perejil.GetDemand(date);
            _valuesDemandNopal[i] = this._nopal.GetDemand(date);
            _valuesDemandStrawberry[i] = this._strawberry.GetDemand(date);
            _valuesDemandPineapple[i] = this._pineapple.GetDemand(date);
            _valuesDemandGuayaba[i] = this._guayaba.GetDemand(date);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            
        }

        private void cbFruit_SelectedIndexChanged(object sender, EventArgs e)
        {
            double times = this.EndDate.Subtract(this.StartDate).TotalDays + 1;

            this.cbFruitDistr.Text = this.cbFruit.Text;
            this.DrawFruitChart(this.cbFruit.Text, this.GetDemandList(), this.GetInventaryList(), _monthsCategery, false, (int)times);
            this.GenerateOutputChart();

            this.pbarSimulation.Visible = false;
            this.lblCostoTotal.Text = "Costo Total: " + this.GetCTF().ToString("C");
        }

        private void cbFruitDistr_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.GenerateDistributionChart();
        }

        private void cbPeriodo_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.GenerateDistributionChart();
        }

        #endregion Event Handlers
    }
}